package com.zhengke.service.bbfx;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.dao.CommonDao;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.MallSupplier;
import com.zhengke.pojo.SalesRank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * *******************************
 * 项目名称：tvmallws
 * 文件名称：SalesRankServiceImpl
 * 类说明：  商品销量排行统计service实现类
 * 创建时间：2020/1/6 13:39
 *
 * @author 王鑫
 * @version 1.0
 * *******************************
 */
@Service
public class SalesRankServiceImpl implements SalesRankService{
    @Autowired
    private CommonDao dao;

    /**
     * 查询商品销售排行统计数据
     * @param areaName
     * @param startDate
     * @param endDate
     * @param start
     * @param size
     * @return
     */
    @Override
    public Result querySalesRank(String areaName, String startDate, String endDate, int start, int size) throws Exception {
        Map<String, String> param = new HashMap<String, String>();
        param.put("areaName", areaName);
        param.put("startDate", startDate);
        param.put("endDate", endDate);


        PageHelper.startPage(start, size, true);
        List<SalesRank> rtnList = (List<SalesRank>) dao.findForList("salesRankMapper.querySaleRank", param);

        System.out.println("querySalesRank------>>>"+ rtnList);

        PageInfo<SalesRank> pageInfo = new PageInfo<SalesRank>(rtnList);

        Result rs = new Result();
        rs.setCode("0");
        rs.setCount(pageInfo.getTotal());
        rs.setData(rtnList);
        return rs;
    }
}
